﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace FormView.UI.AlertView
{
	/// <summary>
	/// AlertFooterBar.xaml 的交互逻辑
	/// </summary>
	public partial class AlertFooterBar : UserControl
	{
		public event Action OnClickPositive;

		public event Action OnClickNeutral;

		public event Action OnClickNegative;

		public AlertFooterBar(string positive = "确定", string negative = null, string neutral = null)
		{
			InitializeComponent();
			OptionInitView(positive, negative, neutral);
		}

		public void OptionInitView(string positive, string negative, string neutral)
		{
			if (positive == null && negative == null && neutral == null)
			{
				throw new ArgumentException("AlertFooter组件不可所有选项均为空");
			}

			Button[] btns = new Button[] {HigherBtn, MiddleBtn, LowerBtn};
			int index = 0;

			if (positive != null)
			{
				btns[index].Content = positive;
				btns[index].Click += (sender, args) => OnClickPositive?.Invoke();
				btns[index].Visibility = Visibility.Visible;
				index += 1;
			}

			if (negative != null)
			{
				btns[index].Content = negative;
				btns[index].Click += (sender, args) => OnClickNegative?.Invoke();
				btns[index].Visibility = Visibility.Visible;
				index += 1;
			}

			if (neutral != null)
			{
				btns[index].Content = neutral;
				btns[index].Click += (sender, args) => OnClickNeutral?.Invoke();
				btns[index].Visibility = Visibility.Visible;
				index += 1;
			}
		}

	}
}
